#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 505;
int g[N][N];
int n;
bool vis[N][N]; //判断是否走过

int dir[4][2] = {
	{0,1},{1,0},{0,-1},{-1,0}
};



void dfs(int x, int y,int z)
{
	if (g[x][y] > z || vis[x][y] || vis[n][n]) return;
	vis[x][y] = 1;
	for (int i = 0; i < 4; i++) {
		int dx = x + dir[i][0], dy = dir[i][1] + y;
		if (dx < 1 || dx > n || dy < 1 || dy >n || vis[dx][dy]) continue;
		dfs(dx, dy, z);
	}

}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin >> g[i][j];
		}
	}
	int  l = 1, r = 1e9, ans = 1e9, md;
	while (l <= r) {
		md = (l + r) >> 1;
		memset(vis, 0, sizeof(vis));
		dfs(1, 1, md);
		if (vis[n][n]) {
			ans = min(ans, md);
			r = md - 1;
		}
		else l = md + 1;
	}
	cout << ans;

	return 0;
}